package com.haina.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.haina.shop.domain.IndexImg;
import com.haina.shop.result.ServiceResult;
import com.haina.shop.service.IndexImgService;
import com.haina.shop.mapper.IndexImgMapper;
import com.haina.shop.vo.IndexImgVO;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
* @author 48077
* @description 针对表【tz_index_img(主页轮播图)】的数据库操作Service实现
* @createDate 2024-07-31 18:34:29
*/
@Service
public class IndexImgServiceImpl extends ServiceImpl<IndexImgMapper, IndexImg>
    implements IndexImgService{
    /**
     * 获取首页轮播图列表信息
     */
    @Override
    public ServiceResult<List<IndexImgVO>> getIndexImgList() {
        List<IndexImg> indexImgList = list();
        List<IndexImgVO> indexImgVOS=new ArrayList<>();
        for (IndexImg indexImg : indexImgList) {
            IndexImgVO vo = getVO(indexImg);
            indexImgVOS.add(vo);
        }
        return ServiceResult.success(indexImgVOS);
    }
    //entity->VO
    public IndexImgVO getVO(IndexImg indexImg){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return new IndexImgVO(
         indexImg.getImgUrl(),indexImg.getSeq(),sdf.format(indexImg.getUploadTime()),
                indexImg.getType(), indexImg.getRelation()
        );
    }
}




